<?php
class Order extends Admin_Controller{
	public function __construct(){
		parent::__construct();
		$this->load->Model(array("Morder"));
	}
	
	public function index(){
		$this->breadcrumb->append_crumb(trans('breadcrumb_home'),admincp_url());
		$this->breadcrumb->append_crumb(trans('breadcrumb_order'),base_url().'admincp/order');
		if($this->input->is_ajax_request()){
            $output = $this->Morder->listOrder();
            $this->output->set_output(json_encode($output));
        }else{
            $data['template']="admincp/order/view";
            $data['title_page']='<i class="icon20 i-list-4"></i> '.trans('title_order');
			$this->load->view("admincp/template",$data);
        }
	}

	public function edit(){
		$id = $this->uri->segment(5);
		$this->breadcrumb->append_crumb(trans('breadcrumb_home'),admincp_url());
		$this->breadcrumb->append_crumb(trans('breadcrumb_order'),base_url().'admincp/order');
		$this->breadcrumb->append_crumb(trans('breadcrumb_order_edit'),base_url().'admincp/order/edit/id/'.$id);
		$data['template']="order/edit";
		$data['title_page']='<i class="icon20 i-pen-2"></i> '.trans('title_order_edit');
		$data['info'] = $this->Morder->get_data($id);
		if($this->input->server('REQUEST_METHOD') == "POST"){
			
			$data_update = array(
				'fullname' => $this->input->post('fullname'),
				'email' => $this->input->post('email'),
				'phone' => $this->input->post('phone'),
				'address' => $this->input->post('address'),
				'note' => $this->input->post('note'),
				'date_update' => date('Y-m-d H:i:s',time()), 
			);
			$this->Morder->update($data_update,$id);
			
			$this->session->set_flashdata(array("success"=>trans('message_edit_successfully')));
			redirect(base_url()."admincp/order");
		}
		$this->load->view("admincp/template",$data);
	}
	
	public function changeStatus(){
		if($this->input->is_ajax_request()){
			$status_id = $this->input->post("status_id");
			$order_id = $this->input->post("order_id");
			$this->Morder->changeStatus($status_id, $order_id);
			echo $html;
		}
	}
}